<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'', styles:'bootstrap,font-awesome,animate,style,bootstrap-table,layui'}){%>
    <style type="text/css">
        body{padding-top:10px;}
        *{margin:0;padding:0;list-style-type:none;}
        a,img{border:0;}
        .demo h2{font-size:16px;color:#3366cc;height:30px;}
        .demo li{float:left;}
    </style>
    <%}%>
</head>

<body>

<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox-content" style="padding:15px 20px 0px 20px;">
                <form id="search-form" role="form" class="form-horizontal">
                    <input type="hidden" readonly id="productMember" name="productMember" class="form-control" value="${user.userRealname}">
                    <div class="form-group">
                        <label class="control-label col-sm-1">海关编号:</label>
                        <div class="col-sm-2">
                            <input type="text" id="refusedNo" name="refusedNo"   class="form-control">
                        </div>
                        <label class="control-label col-sm-1">柜号:</label>
                        <div class="col-sm-2">
                            <input type="text" id="refusedPlanNo" name="refusedPlanNo"   class="form-control">
                        </div>
                        <label class="control-label col-sm-1">状态:</label>
                        <div class="col-sm-2">
                            <select name="flag"  class="form-control">
                                <option value="">请选择</option>
                                <option value="0">未退税</option>
                                <option value="1">已退税</option>
                            </select>
                        </div>

                        <a class="search-btn btn btn-success" style="margin-bottom: 0px;">查询</a>
                    </div>
                </form>
            </div>
            <div id="toolbar" class="btn-group" style="margin-bottom:5px;">


                <button  class="export-btn layui-btn  layui-btn-sm" style="margin-left: -2px">

                    <i class="fa fa-download" aria-hidden="true"></i> 导出当前数据
                </button>

            </div>
            <!-- START 数据表格 -->
            <table id="relatedTable"
                   data-toolbar="#toolbar"
                   data-side-pagination="server"
                   data-pagination="true"
                   data-resizable="true"
                   data-side-pagination="server"
                   data-page-size="15"
                   data-url="/sea/finance/refusedTax/findByCnd.do"
                   class="table table-striped table-hover">
            </table>
            <!-- END 数据表格 -->

            <!-- END 右侧数据 -->
        </div>
    </div>
</div>


<div id="layer_window" style="display: none;overflow-x: hidden;overflow-y: hidden">
    <!-- START 内容部分 -->
    <div class="container" >
        <form class="form-horizontal" id="info-form" method="post" autocomplete="off" style="margin: auto">
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-2" style="max-width: 100px">柜号</label>
                <div class="col-sm-6" style="max-width: 300px">
                    <input type="text" id="createPlanNo" name="createPlanNo" readonly value="" class="form-control">
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-2" style="max-width: 100px">实际退税</label>
                <div class="col-sm-6" style="max-width: 300px">
                    <input type="text" id="createRefusedTotal" name="createRefusedTotal" value="" class="form-control">
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-2" style="max-width: 100px">到账年月</label>
                <div class="col-sm-6" style="max-width: 300px">
                    <input type="text" id="refusedArriveMonth" name="refusedArriveMonth" value="" class="form-control">
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-2" style="max-width: 100px">退税状态</label>
                <div class="col-sm-6" style="max-width: 300px">
                    <select  id="flag" name="flag" class="form-control">
                        <option value="0">未退税</option>
                        <option value="1">已退税</option>
                    </select>
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-7" style="max-width: 100px"></label>
                <button type="button" class="save-btn btn btn-primary">
                    <i class="fa fa-save"></i> 保存
                </button>
            </div>
        </form>
    </div>
    <!-- END 内容部分 -->
</div>

<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,dtvalidate,dtvalidate-lang-zh_cn,bootstrap-table-zh-CN,laydate,layer,layui,upload'}){}%>
<script>

    laydate.render({
        elem: '#refusedArriveMonth',
        type: 'month'
        ,trigger: 'click'
    });
    var $relatedTable = $('#relatedTable'),selections=[];
    $(function(){

        //指定允许上传的文件类型
        //START 表格配置
        $relatedTable.bootstrapTable({
            detailView: true,
            columns: [
                {
                    title: '海关编号',
                    field: 'refusedNo',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '柜号',
                    field: 'refusedPlanNo',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '开船时间',
                    field: 'sendDate',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '实际报关金额',
                    field: 'refusedCreateMoney',
                    align: 'center',
                    valign: 'middle'
                },

                {
                    title: '报关单附件',
                    field: 'refusedOrderFile',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v, r) {
                        if(null != v && v!='') {
                            var result = '<button  class="download-btn layui-btn  layui-btn-sm"  style="margin-top: -6px;margin-left: -4px">';
                            result += '<i class="fa fa-download" aria-hidden="true"></i> <a href="' + v + '" download style="color: white">下载附件</a>';
                            result += '</button>';
                            return result;
                        }else{
                            return '暂无';
                        }
                    }
                },

                {
                    title: '退税凭证',
                    field: 'refusedFile',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v, r) {
                        if(null != v && v!='') {
                            var result = '<button  class="download-btn layui-btn  layui-btn-sm"  style="margin-top: -6px;margin-left: -4px">';
                            result += '<i class="fa fa-download" aria-hidden="true"></i> <a href="' + v + '" download style="color: white">下载附件</a>';
                            result += '</button>';
                            return result;
                        }else{
                            return '暂无';
                        }
                    }
                },
                {
                    title: '应退金额',
                    field: 'refusedMoney',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '实际退税',
                    field: 'createRefusedTotal',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '申报年月',
                    field: 'refusedMonth',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '到账年月',
                    field: 'refusedArriveMonth',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '状态',
                    field: 'flag',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        if(v==0){
                            return '未退税'
                        }else{
                            return '已退税'
                        }
                    }
                },
                {
                    field: 'operate',
                    title: '操作',
                    align: 'center',
                    valign: 'middle',
                    formatter: optFormatter
                }
            ],
            onLoadSuccess : function(){
                $('.add-btn').on('click',function(){
                    var planNo = $(this).attr('data-val');
                    $('#createPlanNo').val(planNo);
                    layer.open({
                        type:1,
                        title:'确认日期',
                        area:['600px','350px'],
                        skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
                        shadeClose:false,
                        resize: false,
                        scrollbar: false,
                        maxmin: false,//出现最大化按钮
                        content:$('#layer_window')
                    })
                });

                $('.edit-btn').on('click',function(){//新增
                    var id=$(this).attr('data-val');
                    layer.open({
                        title: false,
                        closeBtn: 0,
                        type: 2,
                        area: ['100%','100%'],
                        skin: 'layer-ext-espresso',
                        content: ['/sea/finance/refusedTax/editPage.do?id='+id, 'yes']
                    });
                });
            },onExpandRow: function (index, row, $detail) {
                InitSubTable(index, row, $detail);
            }
        });
        //初始化子表格(无线循环)
        function InitSubTable (index, row, $detail) {
            var refusedPlanNo = row.refusedPlanNo;
            var cur_table = $detail.html('<table></table>').find('table');
            $(cur_table).bootstrapTable({
                url: '/sea/finance/refusedTaxRecord/findByCreatePlanNo',
                method: 'get',
                clickToSelect: true,
                queryParams: { createPlanNo: refusedPlanNo},
                ajaxOptions: { createPlanNo: refusedPlanNo },
                clickToSelect: true,
                //height: 500,
                detailView: false,//父子表
                uniqueId: "id",
                pageSize: 10,
                pageList: [10, 25],
                columns: [
                    {
                        field: 'createRefusedTotal',
                        title: '实退金额'
                    },
                    {
                        title: '创建时间',
                        field: 'createTime',
                        align: 'center',
                        valign: 'middle'
                    }],
                onLoadSuccess : function(){

                }
            });
        };
    });


    // 操作菜单
    function optFormatter(value,row){
        var content='';
        if(row.flag==0) {
            content += '<button class="edit-btn btn btn-xs btn-info" data-val="' + row.id + '" title="退税"><i class="fa fa-edit"></i> 退税 </button>';
            content += '&nbsp;<button class="add-btn btn btn-xs btn-success" data-val="'+row.refusedPlanNo+'" title="新增"><i class="fa fa-plus"></i> 实际</button>';
        }
        return content;
    }

    //提交表单
    $('.save-btn').on('click',function(){
        //清关计划
        layer.confirm('确定要修改当前数据？', {
            btn: ['确定','取消'],title:'提示'
        }, function(){
            var createPlanNo=$("#createPlanNo").val();
            var createRefusedTotal=$("#createRefusedTotal").val();
            if(createRefusedTotal==''){
                parent.layer.msg('请填写实退金额！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            layer.closeAll();
            var index=layer.load();
            $.post('/sea/finance/refusedTaxRecord/save.do',{createPlanNo:createPlanNo,createRefusedTotal:createRefusedTotal,flag:$("#flag").val(),refusedArriveMonth:$("#refusedArriveMonth").val()},function(data){
                if( data.ok ){
                    $relatedTable.bootstrapTable('refresh');
                    layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }else{
                    layer.msg(data.msg,{icon: 0,time:5000,shade: [0.8, '#393D49']});
                    layer.close(index);
                }
            });
        });
    });


    $('.search-btn').on('click',function(){
        $relatedTable.bootstrapTable('refresh', { url:'${ctxPath}/sea/finance/refusedTax/findByCnd.do?'+$('#search-form').serialize() });
    });



    $(".export-btn").click(function () {
        window.location.href='/sea/finance/refusedTax/export?'+$('#search-form').serialize();
    });
</script>
</body>
</html>
